import axios from "axios";

const API_URL = "http://localhost:9000";

export default class ProjectReportManagementService {
  // 获取所有项目报告
  static async getAllProjectReports(): Promise<any[]> {
    try {
      const response = await axios.get(`${API_URL}/projectReport/getAll`);
      return response.data;
    } catch (error) {
      console.error("Failed to get all project reports:", error);
      throw error;
    }
  }

  // 通过ID获取项目报告
  static async getProjectReportById(id: number): Promise<any> {
    try {
      const response = await axios.get(`${API_URL}/projectReport/getById`, {
        params: { id },
      });
      return response.data;
    } catch (error) {
      console.error(`Failed to get project report by id ${id}:`, error);
      throw error;
    }
  }
  // ModuleController 相关方法
  static async getAllModules() {
    try {
      const response = await axios.get(`${API_URL}/module/getAll`);
      return response.data;
    } catch (error) {
      console.error("Failed to get all modules:", error);
      throw error;
    }
  }

  static async getModuleById(id: any) {
    try {
      const response = await axios.get(`${API_URL}/module/getById`, {
        params: { id },
      });
      return response.data;
    } catch (error) {
      console.error(`Failed to get module by id ${id}:`, error);
      throw error;
    }
  }

  static async getModuleBySubsystemId(subId: any) {
    try {
      const response = await axios.get(`${API_URL}/module/getBySubId`, {
        params: { subId },
      });
      return response.data;
    } catch (error) {
      console.error("根据id加载模块错误:", error);
      throw error;
    }
  }

  // ReportAnnotationController 相关方法
  static async getAllReportAnnotations() {
    try {
      const response = await axios.get(`${API_URL}/reportAnnotation/getAll`);
      return response.data;
    } catch (error) {
      console.error("Failed to get all report annotations:", error);
      throw error;
    }
  }

  static async getReportAnnotationById(id: any) {
    try {
      const response = await axios.get(`${API_URL}/reportAnnotation/getById`, {
        params: { id },
      });
      return response.data;
    } catch (error) {
      console.error(`没有获取批注ID ${id}:`, error);
      throw error;
    }
  }

  static async getReportAnnotationByReportId(reportId: any) {
    try {
      const response = await axios.get(
        `${API_URL}/reportAnnotation/getByReportId`,
        { params: { reportId } }
      );
      return response.data;
    } catch (error) {
      console.error(`没有获取批注的项目ID ${reportId}:`, error);
      throw error;
    }
  }

  // ReportContentController 相关方法
  static async getAllReportContents() {
    try {
      const response = await axios.get(`${API_URL}/reportContent/getAll`);
      return response.data;
    } catch (error) {
      console.error("Failed to get all report contents:", error);
      throw error;
    }
  }

  static async getReportContentByReportId(reportId: any) {
    try {
      const response = await axios.get(
        `${API_URL}/reportContent/getByReportId`,
        { params: { reportId } }
      );
      return response.data;
    } catch (error) {
      console.error(`Failed to get report content by id ${reportId}:`, error);
      throw error;
    }
  }
  static async getReportContentById(id: any) {
    try {
      const response = await axios.get(`${API_URL}/reportContent/getById`, {
        params: { id },
      });
      return response.data;
    } catch (error) {
      console.error(`Failed to get report content by id ${id}:`, error);
      throw error;
    }
  }

  // 获取reportId和reportName
  static async getReportIdAndReportName(): Promise<any[]> {
    try {
      const response = await axios.get(
        `${API_URL}/projectReport/getReportIdAndReportName`
      );
      return response.data;
    } catch (error) {
      console.error("Failed to get reportId and reportName:", error);
      throw error;
    }
  }

  static async getModulesByReportId(reportId: any) {
    try {
      const response = await axios.get(
        `${API_URL}/module/getModulesByReportId`,
        {
          params: { reportId },
        }
      );
      return response.data;
    } catch (error) {
      console.error(`Failed to get modules by report id ${reportId}:`, error);
      throw error;
    }
  }

  // SubSystemController 相关方法
  static async getSubSystemsByReportId(reportId: any) {
    try {
      const response = await axios.get(`${API_URL}/subSystem/getByReportId`, {
        params: { reportId },
      });
      return response.data;
    } catch (error) {
      console.error("根据id加载系统错误:", error);
      throw error;
    }
  }
  // SubSystemController 相关方法
  static async getAllSubSystems() {
    try {
      const response = await axios.get(`${API_URL}/subSystem/getAll`);
      return response.data;
    } catch (error) {
      console.error("Failed to get all subsystems:", error);
      throw error;
    }
  }

  static async getSubSystemById(id: number) {
    try {
      const response = await axios.get(`${API_URL}/subSystem/getByReportId`, {
        params: { reportId: id },
      });
      return response.data;
    } catch (error) {
      console.error(`Failed to get subsystem by id ${id}:`, error);
      throw error;
    }
  }
}
